*** One-Child Policy, Marriage Distortion, and Welfare Loss ***
*** by Wei Huang, Yinghao Pan and Yi Zhou ***

clear all 
set more off
set scheme s1color
cap log close 
graph set window fontface "Times New Roman"

set niceness 10
gl MAIN = "F:\Dropbox"

gl path1 = "$MAIN/Census"
gl path2 = "$MAIN/Marriage/Working_data"
gl path3 = "$MAIN/Marriage/Restat/dataverse_files/Results" 
gl path4 = "$MAIN/Marriage/Restat/dataverse_files/Graphics" 
gl CONTROL = " year_birth sex#age urban_hk prov_hk##c.(year_birth ) "



******** Appendix Figure A9 **************
  

use "$path2/unmarried", clear
keep if relation == 0 | relation == 1 | relation == 2 | relation == 6 

merge 1:1 wave area hhid name relation using "$path2/min_marr_policy", keepusing(marry_1 marry_2 marry_3)


drop if mi(hktype)
replace urban = hktype == 1 
su age 

cap gen female = 1-male
cap gen han = 1- minority 

replace unmarried = unmarried * 100 
gen unmarr_25 = marr_age > 25 if !mi(marr_age)
replace unmarr_25 = 1 if unmarried == 100 
replace unmarr_25 = unmarr_25 *100 

gen urban_hk = hktype == 2 

egen clsid = group(prov_hk year_birth)

gen marry_9 = unmarried == 0 & (mi(marry_1) & mi(marry_2) & mi( marry_3))

recode marry_1 marry_2 marry_3 (. = 0) 

gen HH = marry_1 * 100 
gen HM = marry_2 * 100 
gen MM = marry_3 * 100 
gen Other = marry_9 * 100 
gen HOMO = HH + MM
su HOMO

keep if age <= 55
keep if age > 25
keep if year_birth <= 1980
keep if Other == 0 

cap noi: program drop coef

program define coef
syntax, gender(string) y_var(string) eth(string) policy(string) sample(string) [title(string)]
preserve 
keep if  `policy' & `gender' & `eth'
reghdfe `y_var' fine_16_25 [aw = aw] if `sample', a($CONTROL)  cl(prov_hk)
est store `y_var'`title'
restore
end

foreach y_var in  "unmarried" "HOMO" "HM"  {
coef, gender(sex == 1) y_var(`y_var') eth(han == 1) policy(1) title(full_han_male)  sample(1)
coef, gender(sex == 2) y_var(`y_var') eth(han == 1) policy(1) title(full_han_female) sample(1)
coef, gender(sex == 1) y_var(`y_var') eth(han == 1) policy(mino_policy == 1) title(pre_han_male) sample(1)
coef, gender(sex == 2) y_var(`y_var') eth(han == 1) policy(mino_policy == 1) title(pre_han_female) sample(1)
coef, gender(sex == 1) y_var(`y_var') eth(han == 1) policy(mino_policy == 0) title(nopre_han_male) sample(1)
coef, gender(sex == 2) y_var(`y_var') eth(han == 1) policy(mino_policy == 0) title(nopre_han_female) sample(1)

coef, gender(sex == 1) y_var(`y_var') eth(han == 0) policy(1) title(full_min_male) sample(1)
coef, gender(sex == 2) y_var(`y_var') eth(han == 0) policy(1) title(full_min_female)  sample(1)
coef, gender(sex == 1) y_var(`y_var') eth(han == 0) policy(mino_policy == 1) title(pre_min_male)  sample(1)
coef, gender(sex == 2) y_var(`y_var') eth(han == 0) policy(mino_policy == 1) title(pre_min_female)  sample(1)
coef, gender(sex == 1) y_var(`y_var') eth(han == 0) policy(mino_policy == 0) title(nopre_min_male) sample(1)
coef, gender(sex == 2) y_var(`y_var') eth(han == 0) policy(mino_policy == 0) title(nopre_min_female) sample(1)
}


foreach y_var in  "HM"  {
coef, gender(sex == 1) y_var(`y_var') eth(han == 1) policy(1) title(full_han_male_con)  sample(unmarried == 0)
coef, gender(sex == 2) y_var(`y_var') eth(han == 1) policy(1) title(full_han_female_con) sample(unmarried == 0)
coef, gender(sex == 1) y_var(`y_var') eth(han == 1) policy(mino_policy == 1) title(pre_han_male_con) sample(unmarried == 0)
coef, gender(sex == 2) y_var(`y_var') eth(han == 1) policy(mino_policy == 1) title(pre_han_female_con) sample(unmarried == 0)
coef, gender(sex == 1) y_var(`y_var') eth(han == 1) policy(mino_policy == 0) title(nopre_han_male_con) sample(unmarried == 0)
coef, gender(sex == 2) y_var(`y_var') eth(han == 1) policy(mino_policy == 0) title(nopre_han_female_con) sample(unmarried == 0)

coef, gender(sex == 1) y_var(`y_var') eth(han == 0) policy(1) title(full_min_male_con) sample(unmarried == 0)
coef, gender(sex == 2) y_var(`y_var') eth(han == 0) policy(1) title(full_min_female_con)  sample(unmarried == 0)
coef, gender(sex == 1) y_var(`y_var') eth(han == 0) policy(mino_policy == 1) title(pre_min_male_con)  sample(unmarried == 0)
coef, gender(sex == 2) y_var(`y_var') eth(han == 0) policy(mino_policy == 1) title(pre_min_female_con)  sample(unmarried == 0)
coef, gender(sex == 1) y_var(`y_var') eth(han == 0) policy(mino_policy == 0) title(nopre_min_male_con) sample(unmarried == 0)
coef, gender(sex == 2) y_var(`y_var') eth(han == 0) policy(mino_policy == 0) title(nopre_min_female_con) sample(unmarried == 0)
}

lab var unmarried "Unmarried"
lab var HOMO "Intra-ethnic Marriage"
lab var HM "Inter-ethnic Marriage"

cap noi: program drop ciplot

program define ciplot
syntax,  y_var(string) eth(string)  [con(string)]
loc ytitl:var label `y_var'
coefplot (`y_var'full_`eth'_male`con' ,  mlabel("Male") ciopts(lpattern(dash) recast(rcap) lc(orange_red)))  ///
(`y_var'full_`eth'_female`con' , mlabel("Female") mc(dkgreen) ciopts(lpattern(dash) recast(rcap) lc(orange_red))) ///
(`y_var'pre_`eth'_male`con' ,  mlabel("Male")    mc(dkgreen) ciopts(lpattern(dash) recast(rcap) lc(orange_red)))  ///
(`y_var'pre_`eth'_female`con' , mlabel("Female")  mc(dkgreen) ciopts(lpattern(dash) recast(rcap) lc(orange_red))) ///
(`y_var'nopre_`eth'_male`con' ,  mlabel("Male")  mc(dkgreen) ciopts(lpattern(dash) recast(rcap) lc(orange_red)))  ///
(`y_var'nopre_`eth'_female`con' , mlabel("Female")  mc(dkgreen) ciopts(lpattern(dash) recast(rcap) lc(orange_red))) ///
, xline(0,lp(dash))  bycoefs byopts(yrescale)  ///
text(0.53 -5 "Panel A: All Regions",size(*0.8) place(right)) ///
text(0.83 -5 "Panel B: Regions with Preferential Policy",size(*0.8) place(right)) ///
text(1.13 -5 "Panel C: Regions without Preferential Policy",size(*0.8) place(right)) ///
drop(_cons) bylabels(" ")  legend(order(2 "Coef." 1 "95% CI" ) ring(0)pos(7) rows(1)  ) xlabel(-5/5) xtit("Coef. and CI of Fine at 16-25 (`ytitl')")  mlabposition(12) mlabc(dkgreen)
graph export $path4/`y_var'_`eth'`con'.pdf, replace
end


foreach y_var in  "unmarried"  {
foreach eth in "han" "min"{
ciplot, y_var(`y_var') eth(`eth') 
}
}

foreach y_var in  "HM"  {
foreach eth in "han" "min"{
ciplot, y_var(`y_var') eth(`eth') con(_con)
}
}



